package com.geodroid.common.kernel.algos ;





import com.geodroid.common.kernel.geos.GeoElement;
import com.geodroid.common.kernel.geos.GeoPoint2;
import com.geodroid.common.kernel.geos.GeoSegment;
import com.geodroid.common.kernel.geos.GeoVec3D;




public class AlgoJoinPointsSegment extends AlgoElement {

	private GeoPoint2 P, Q; // input
    private GeoSegment s; // output: GeoSegment subclasses GeoLine 
	
    
    /** Creates new AlgoJoinPoints */
    public AlgoJoinPointsSegment(
        GeoPoint2 P,
        GeoPoint2 Q) {
    
        this.P = P;
        this.Q = Q;
    
        s = new GeoSegment(P, Q);
        setInputOutput(); // for AlgoElement
        
        compute();
        setIncidence();
    }

    private void setIncidence() {
    	P.addIncidence(s);
    	Q.addIncidence(s);
	}
    
	@Override
	protected void compute() {
    	GeoVec3D.lineThroughPoints(P, Q, s);  

	}

    public GeoSegment getSegment() {
        return s;
    }
    GeoPoint2 getP() {
        return P;
    }
    GeoPoint2 getQ() {
        return Q;
    }
	
	@Override
	protected void setInputOutput() {
    		input = new GeoElement[2];
    		input[0] = P;
            input[1] = Q;
                	    	
            GeoElement [] out = new GeoElement[1] ;
            out[0] = s ; 
            setOutput(out) ; 
          
            setDependencies();

	}


	/* (non-Javadoc)
	 * @see com.geodroid.common.kernel.algos.AlgoElement#hasOutputChangeable()
	 */
	@Override
	public boolean hasOutputChangeable() {
		return this.P.isMoveable() && this.Q.isMoveable() ;
	}
	
	

}
